﻿using System;
using System.Threading;

public class AlarmClock
{
    public event EventHandler Tick;
    public event EventHandler Alarm;

    private bool alarmTriggered = false;

    public void Start(int tickInterval, int alarmTime)
    {
        int timeElapsed = 0;
        while (!alarmTriggered)
        {
            Thread.Sleep(tickInterval);
            timeElapsed += tickInterval;
            Console.WriteLine($"Tick: {timeElapsed / 1000} seconds");
            Tick?.Invoke(this, EventArgs.Empty);

            if (timeElapsed >= alarmTime)
            {
                alarmTriggered = true;
                Console.WriteLine("Alarm!");
                Alarm?.Invoke(this, EventArgs.Empty);
            }
        }
    }
}

class Program2
{
    static void Main()
    {
        AlarmClock clock = new AlarmClock();

        clock.Tick += (sender, e) => Console.WriteLine("Tick event received.");
        clock.Alarm += (sender, e) => Console.WriteLine("Alarm event received.");

        int tickInterval = 1000; // 1 second
        int alarmTime = 5000; // 5 seconds

        Console.WriteLine("Starting clock...");
        clock.Start(tickInterval, alarmTime);
        Console.WriteLine("Clock stopped.");
    }
}